package com.example.myapplication

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.plusAssign
import com.example.myapplication.databinding.ActivityMainBinding
import com.example.mylibrary.utils.StatusBar
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    @Inject
    lateinit var homeNavigator: HomeNavigator
    private val navController: NavController by lazy {
        findNavController(R.id.nav_host_fragment)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        StatusBar.lightStatusBar(this, false)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment)
        val navigator = navHostFragment?.childFragmentManager?.let {
            KeepStateNavigator(this, it, R.id.nav_host_fragment)
        }
        navigator?.let {
            navController.navigatorProvider += it
        }
        navController.setGraph(R.navigation.nav_graph)
        homeNavigator.bindNavController(navController)
    }
}
